from django.contrib import admin
from .models import ExerciseSet, Exercise, UserExerciseRecord, UserExerciseSetProgress

@admin.register(ExerciseSet)
class ExerciseSetAdmin(admin.ModelAdmin):
    list_display = ('title', 'created_by', 'created_at', 'is_public', 'questions_count')
    list_filter = ('is_public', 'created_at')
    search_fields = ('title', 'description', 'created_by__username')
    date_hierarchy = 'created_at'

@admin.register(Exercise)
class ExerciseAdmin(admin.ModelAdmin):
    list_display = ('id', 'exercise_set', 'question_type', 'difficulty', 'created_at')
    list_filter = ('question_type', 'difficulty', 'created_at')
    search_fields = ('content', 'answer', 'exercise_set__title')
    date_hierarchy = 'created_at'

@admin.register(UserExerciseRecord)
class UserExerciseRecordAdmin(admin.ModelAdmin):
    list_display = ('user', 'exercise', 'status', 'created_at', 'updated_at')
    list_filter = ('status', 'created_at')
    search_fields = ('user__username', 'exercise__content')
    date_hierarchy = 'created_at'

@admin.register(UserExerciseSetProgress)
class UserExerciseSetProgressAdmin(admin.ModelAdmin):
    list_display = ('user', 'exercise_set', 'completed_count', 'correct_count', 'is_completed', 'progress_percentage')
    list_filter = ('is_completed', 'started_at')
    search_fields = ('user__username', 'exercise_set__title')
    date_hierarchy = 'started_at'
